<?php
/**
 * WpJsonView.php
 * 
 * This files contains the class WpJsonView, a view for WildPack mvc
 * @author Robert Schmidt <robert@wildpack.de>
 * @version 1.0
 * @package wildpack
 * @subpackage mvc.view
 */

/**
 * The interface to implement
 */
require_once (dirname(__FILE__).'/IWpView.php');

/**
 * This view converts the provided data into a json string and delivers 
 * the string to the response
 * @author Robert Schmidt <robert@wildpack.de>
 * @version 1.0
 * @package wildpack
 * @subpackage mvc.view
 */
class WpJsonView
{
	public $Data = array();
	
	/**
	 * The class constructor
	 */
	public function __construct($config = null) {}
	
	/**
   * Assigns data to the view
   * @param mixed $data The data to assign to the view
   */
	public function assign($data)
	{
		foreach ($data as $key => $dentry) {
			$this->Data[$key] = $dentry;
		}
	}
	
	/**
   * Renders the view and returns the content
   * @param object $viewname[optional] The name of the view to render
   * @return string The rendered view as string
   */
	public function fetch($viewname = '')
	{
		return json_encode($this->Data);
	}
	
	/**
   * Renders the view
   * @param string $viewname The name of the view to render
   * @param object $response The response to write the rendered view to
   */
	public function render($response)
	{
		$response->write(json_encode($this->Data));
		$response->flush();
	}
	
	/**
   * Specifies the name of the view to use
   * @param string $viewname The name of the view to use
   */
	public function setViewname($viewname) {}
}

/* End of file WpJsonView.php */
/* Location: ./wildpack/mvc/view/WpJsonView.php */
